/// <reference path='../../node_modules/@angular/core/src/util/decorators.d.ts' />
import { Component, ComponentDecorator, Directive, ChangeDetectionStrategy } from '@angular/core';
import { PlatformComponentWrapper, PlatformClassDistribute } from './mutil.platform';
import { makeDecorator } from './make.derator';


export const MyComponent: ComponentDecorator = <ComponentDecorator>makeDecorator(
  'Component', PlatformComponentWrapper2,
  Directive);

function PlatformComponentWrapper2(componentMetadata: Component = {}): Component {
  console.log(componentMetadata);

  if (componentMetadata && componentMetadata.templateUrl) {
    const templateUrl = componentMetadata.templateUrl;
    const pointHtml = templateUrl.lastIndexOf('.');
    const platformTemplateUrl = templateUrl.substring(0, pointHtml)
      + '.'
      + 'pc'
      + templateUrl.substring(pointHtml);

    componentMetadata.templateUrl = platformTemplateUrl;
  }
  console.log(componentMetadata);
  return { changeDetection: ChangeDetectionStrategy.Default, ...componentMetadata };
}

@PlatformClassDistribute()
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  title = 'app';
}
